home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
526-550
/
disk_534
/
term
/
source.lzh
/
termRaster.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-17
|
9KB
|
495 lines
/* $Revision Header * Header built automatically - do not edit! *************
*
* (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
*
* Name .....: Serial.c
* Created ..: Saturday 02-Mar-91 18:30
* Revision .: 0
*
* Date Author Comment
* ========= ======== ====================
* 02-Mar-91 Olsen Created this file!
*
* $Revision Header ********************************************************/
#include "termGlobal.h"
/* RasterMarkArea(SHORT Column,SHORT Line,SHORT Length):
*
* Mark an area in the term Buffer window.
*/
VOID
RasterMarkArea(SHORT Column,SHORT Line,SHORT Length)
{
STATIC SHORT OldColumn = -1,OldLine = -1,OldLength = -1;
if(OldColumn != Column || OldLine != Line || OldLength != Length)
{
if(OldColumn != -1)
ClipBlit(RPort,0,0,RPort,OldColumn << 3,OldLine << 3,OldLength << 3,8,0x50);
ClipBlit(RPort,0,0,RPort,Column << 3,Line << 3,Length << 3,8,0x50);
}
OldColumn = Column;
OldLine = Line;
OldLength = Length;
}
/* RasterClip():
*
* Put a character raster portion into the clipboard.
*/
VOID
RasterClip(BYTE SingleChar,BYTE Xerox)
{
struct IntuiMessage *Massage;
ULONG Code,Class;
BYTE SkipLoop = FALSE;
LONG ThisLine,ThisColumn,MyColumn,SomeColumn;
UBYTE *TheLine;
/* Remember initial mouse position. */
ThisColumn = Window -> MouseX >> 3;
ThisLine = Window -> MouseY >> 3;
if(ThisColumn <= LastColumn && ThisLine <= LastLine)
{
RasterMarkArea(-1,-1,-1);
/* Find the approriate line and its length. */
TheLine = &Raster[RasterWidth * ThisLine];
if(SingleChar)
{
if(TheLine[ThisColumn] && TheLine[ThisColumn] != ' ')
{
SerWrite(&TheLine[ThisColumn],1);
if(Xerox)
{
switch(Config . SendCR)
{
case CR_IGNORE: break;
case CR_ASCR: SerWrite("\r",1);
break;
case CR_ASCRLF: SerWrite("\r\n",2);
break;
}
}
}
return;
}
/* Resonable dimensions? */
if(ThisColumn <= LastColumn)
{
MyColumn = ThisColumn;
/* Loop until left mouse button is release. */
while(!SkipLoop)
{
WaitPort(Window -> UserPort);
while(Massage = (struct IntuiMessage *)GetMsg(Window -> UserPort))
{
Class = Massage -> Class;
Code = Massage -> Code;
ReplyMsg(Massage);
/* We're finished! */
if(Class == IDCMP_MOUSEBUTTONS && Code == SELECTUP)
{
SkipLoop = TRUE;
/* Did we get a reasonable mouse
* position?
*/
if(MyColumn != ThisColumn)
{
/* Preserve right order of
* numbers.
*/
if(MyColumn < ThisColumn)
{
LONG Help;
Help = ThisColumn;
ThisColumn = MyColumn;
MyColumn = Help;
}
RasterMarkArea(-1,-1,-1);
/* Clip the contents of the line to
* the clipboard.
*/
SaveClip(&TheLine[ThisColumn],MyColumn - ThisColumn);
if(Xerox)
{
SerWrite(&TheLine[ThisColumn],MyColumn - ThisColumn);
switch(Config . SendCR)
{
case CR_IGNORE: break;
case CR_ASCR: SerWrite("\r",1);
break;
case CR_ASCRLF: SerWrite("\r\n",2);
break;
}
}
}
break;
}
/* The mouse has moved. */
if(Class == IDCMP_MOUSEMOVE)
{
STATIC LONG OldColumn = ~0;
/* Determine new mouse position. */
SomeColumn = MyColumn;
MyColumn = Massage -> MouseX >> 3;
if((Massage -> MouseY >> 3) < ThisLine)
MyColumn = 0;
if((Massage -> MouseY >> 3) > ThisLine)
MyColumn = LastColumn + 1;
/* Don't redraw the line if nothing
* has changed.
*/
if(OldColumn != MyColumn)
{
OldColumn = MyColumn;
/* Reasonable position? */
if(MyColumn <= LastColumn + 1)
{
if(MyColumn >= 0)
{
/* Highlight the selected
* area (invert).
*/
if(MyColumn != ThisColumn)
{
if(MyColumn < ThisColumn)
RasterMarkArea(MyColumn,ThisLine,ThisColumn - MyColumn);
else
RasterMarkArea(ThisColumn,ThisLine,MyColumn - ThisColumn);
}
}
}
else
MyColumn = SomeColumn;
}
}
}
}
}
}
}
/* DeleteRaster():
*
* Free the contents of the character raster.
*/
VOID
DeleteRaster()
{
if(Raster)
{
FreeVec(Raster);
Raster = NULL;
}
}
/* CreateRaster():
*
* Create the character raster.
*/
BYTE
CreateRaster()
{
/* Width of the screen (in characters). */
RasterWidth = Window -> Width >> 3;
/* Height of the character raster. */
RasterHeight = Window -> Height >> 3;
/* Allocate the raster. */
if(Raster = (UBYTE *)AllocVec(RasterWidth * RasterHeight * 2,MEMF_PUBLIC|MEMF_CLEAR))
return(TRUE);
else
return(FALSE);
}
/* RasterEraseScreen(BYTE Mode):
*
* Erase parts of the screen.
*/
VOID
RasterEraseScreen(BYTE Mode)
{
SHORT First,Last;
switch(Mode)
{
case 1: First = 0;
Last = CursorY * RasterWidth + CursorX;
break;
case 2: First = 0;
Last = (RasterHeight + 1) * RasterWidth - 1;
break;
default:First = CursorY * RasterWidth;
Last = (RasterHeight + 1) * RasterWidth - 1;
break;
}
memset(&Raster[First],' ',Last - First);
}
/* RasterEraseLine(BYTE Mode):
*
* Erase parts of the current cursor line.
*/
VOID
RasterEraseLine(BYTE Mode)
{
SHORT First,Last;
switch(Mode)
{
case 1: First = CursorY * RasterWidth;
Last = First + CursorX;
break;
case 2: First = CursorY * RasterWidth;
Last = First + RasterWidth - 1;
break;
default:First = CursorY * RasterWidth + CursorX;
Last = (CursorY + 1) * RasterWidth - 1;
break;
}
memset(&Raster[First],' ',Last - First);
}
/* RasterEraseCharacters(SHORT Chars):
*
* Erase a number of characters in the current cursor
* line.
*/
VOID
RasterEraseCharacters(SHORT Chars)
{
SHORT i,First,Diff = RasterWidth - CursorX;
UBYTE *FirstPtr,*LastPtr;
First = CursorY * RasterWidth + CursorX;
FirstPtr = &Raster[First];
LastPtr = &Raster[First + Chars];
i = 0;
while(i++ < Diff)
{
*FirstPtr++ = *LastPtr;
*LastPtr++ = ' ';
}
}
/* RasterClearLine(SHORT Lines):
*
* Clear the current line.
*/
VOID
RasterClearLine(SHORT Lines)
{
memset(&Raster[CursorY * RasterWidth],' ',Lines * RasterWidth);
}
/* RasterInsertLine(SHORT Lines):
*
* Insert a number of lines at the current cursor line.
*/
VOID
RasterInsertLine(SHORT Lines)
{
if(CursorY + Lines > RasterHeight)
RasterEraseScreen(0);
else
{
SHORT First,Last,i,Max = Lines * RasterWidth;
UBYTE *FirstPtr,*LastPtr;
First = (LastLine - Lines + 2) * RasterWidth - 1;
Last = (LastLine + 2) * RasterWidth - 1;
FirstPtr = &Raster[First];
LastPtr = &Raster[Last];
i = 0;
while(i++ < Max)
*LastPtr-- = *FirstPtr--;
RasterClearLine(Lines);
}
}
/* RasterScrollRegion(BYTE Direction):
*
* Scroll the contents of the character raster up/down.
*/
VOID
RasterScrollRegion(BYTE Direction)
{
SHORT RasterTop,RasterBottom,RasterLines;
if(UseRegion)
{
RasterTop = Top;
RasterBottom = Bottom;
RasterLines = Bottom - Top;
}
else
{
RasterTop = 0;
RasterBottom = LastLine + 1;
RasterLines = LastLine + 1;
}
if(Direction < 0)
{
SHORT First,Last,i,Max = RasterLines * RasterWidth;
UBYTE *FirstPtr,*LastPtr;
First = (RasterTop + RasterLines ) * RasterWidth - 1;
Last = (RasterTop + RasterLines + 1) * RasterWidth - 1;
FirstPtr = &Raster[First];
LastPtr = &Raster[Last];
i = 0;
while(i++ < Max)
*LastPtr-- = *FirstPtr--;
memset(&Raster[RasterTop * RasterWidth],' ',RasterWidth);
}
else
{
SHORT First,Last,i,Max = RasterLines * RasterWidth;
UBYTE *FirstPtr,*LastPtr;
First = RasterTop * RasterWidth + RasterWidth;
Last = RasterTop * RasterWidth;
FirstPtr = &Raster[First];
LastPtr = &Raster[Last];
i = 0;
while(i++ < Max)
*LastPtr++ = *FirstPtr++;
memset(&Raster[RasterLines * RasterWidth],' ',RasterWidth);
}
}
/* RasterShiftChar():
*
* Shift the characters following the current cursor
* position one character to the right.
*/
VOID
RasterShiftChar()
{
SHORT i,First;
UBYTE *FirstPtr,*LastPtr;
First = CursorY * RasterWidth;
FirstPtr = &Raster[First + RasterWidth - 1];
LastPtr = &Raster[First + RasterWidth - 1 - 1];
i = RasterWidth - 1;
while(i-- > CursorX)
*FirstPtr-- = *LastPtr--;
}
/* RasterPutString(UBYTE *String,SHORT Length):
*
* Put a string into the character raster.
*/
VOID
RasterPutString(UBYTE *String,SHORT Length)
{
SHORT X = CursorX;
if(Config . FontScale != SCALE_HALF)
{
if(X && Config . InsertChar)
X--;
if(Length == 1)
{
if(X + 1 < RasterWidth)
Raster[CursorY * RasterWidth + X] = String[0];
}
else
{
if(X + Length >= RasterWidth)
Length = RasterWidth - X;
CopyMem(String,&Raster[CursorY * RasterWidth + X],Length);
}
}
}